/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.juego.endpointwebsocket.encoder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

/**
 *
 * @author MoisesAntonio
 */
public class EncEscenario implements Encoder.Binary<File>{

    @Override
    public ByteBuffer encode(File o) throws EncodeException {
        FileInputStream f;
        try {
            f = new FileInputStream(o);
            int size=(int)o.length();
            byte[] array=new byte[size];
            int n=f.read(array);
            ByteBuffer buffer= ByteBuffer.allocate(size);
            buffer.put(array);
            return buffer;
        } catch (FileNotFoundException ex) {
            Logger.getLogger(EncEscenario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(EncEscenario.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return null;
    }

    @Override
    public void init(EndpointConfig config) {    }

    @Override
    public void destroy() {    }

}
